package com.apimanage.gateway.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 限流配置属性类
 */
@Component
@ConfigurationProperties(prefix = "gateway.rate-limit")
public class RateLimitProperties {

    /**
     * 是否启用限流
     */
    private boolean enabled = false;
    
    /**
     * 每秒最大请求数
     */
    private int requestsPerSecond = 10;
    
    /**
     * 限流策略：ip、user、path
     */
    private String strategy = "ip";
    
    /**
     * 不需要限流的路径列表
     */
    private List<String> excludePaths;
    
    /**
     * 特殊路径的限流配置
     */
    private List<PathRateLimitConfig> pathConfigs;

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public int getRequestsPerSecond() {
        return requestsPerSecond;
    }

    public void setRequestsPerSecond(int requestsPerSecond) {
        this.requestsPerSecond = requestsPerSecond;
    }

    public String getStrategy() {
        return strategy;
    }

    public void setStrategy(String strategy) {
        this.strategy = strategy;
    }

    public List<String> getExcludePaths() {
        return excludePaths;
    }

    public void setExcludePaths(List<String> excludePaths) {
        this.excludePaths = excludePaths;
    }

    public List<PathRateLimitConfig> getPathConfigs() {
        return pathConfigs;
    }

    public void setPathConfigs(List<PathRateLimitConfig> pathConfigs) {
        this.pathConfigs = pathConfigs;
    }

    /**
     * 路径限流配置类
     */
    public static class PathRateLimitConfig {
        private String pathPattern;
        private int requestsPerSecond;
        
        public String getPathPattern() {
            return pathPattern;
        }
        
        public void setPathPattern(String pathPattern) {
            this.pathPattern = pathPattern;
        }
        
        public int getRequestsPerSecond() {
            return requestsPerSecond;
        }
        
        public void setRequestsPerSecond(int requestsPerSecond) {
            this.requestsPerSecond = requestsPerSecond;
        }
    }
}